package com.jysz.certificate.persistence.model.system;

import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.google.gson.annotations.Expose;
import com.jysz.certificate.persistence.enums.PostType;
import com.jysz.webcore.ssh.entity.AbstractBaseEntity;

@Entity
@Table(name = "sys_user_")
@org.hibernate.annotations.Entity
public class User extends AbstractBaseEntity<Long> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Expose
	private String name;
	private String locked;//状态
	private String password;//
	private String sex;
	private String telephone;//手机
	@Expose
	private String realName;//用户名称
	private Date birthday;
	private String email;
	
	@Expose
	private String jobNumber;//工号
	private Date entryDate;
	private PostType post;//角色
	private Shop shop;//销售店
	private Set<Role> roles;
	

	@Column(name = "_name", nullable = false, unique = true,columnDefinition="varchar(255)")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		name = name.replace(" ", "");
		this.name = name;
	}

	@Column(name = "_locked",columnDefinition="varchar(2)")
	public String getLocked() {
		return locked;
	}

	public void setLocked(String locked) {
		this.locked = locked;
	}

	@Column(name = "_password",columnDefinition="varchar(255)")
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "_sex",columnDefinition="varchar(2)")
	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	@Column(name = "_telephone",columnDefinition="varchar(255)")
	public String getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	@Column(name = "_realName",columnDefinition="varchar(255)")
	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	@Column(name = "_birthday")
	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	@Column(name = "_email",columnDefinition="varchar(255)")
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "_jobNumber",columnDefinition="varchar(255)")
	public String getJobNumber() {
		return jobNumber;
	}

	public void setJobNumber(String jobNumber) {
		this.jobNumber = jobNumber;
	}

	@Column(name = "_entryDate")
	public Date getEntryDate() {
		return entryDate;
	}

	public void setEntryDate(Date entryDate) {
		this.entryDate = entryDate;
	}
	
	@Column(name = "_post",columnDefinition="int(11)")
	@Enumerated(EnumType.ORDINAL)
	public PostType getPost() {
		return post;
	}

	public void setPost(PostType post) {
		this.post = post;
	}

	@ManyToOne(fetch = FetchType.LAZY)  
	@JoinColumn(name = "_shop_id",columnDefinition="bigint(20)") 
	public Shop getShop() {
		return shop;
	}

	public void setShop(Shop shop) {
		this.shop = shop;
	}


	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "rs_sys_user__sys_role_", joinColumns = @JoinColumn(name = "_user_id"), inverseJoinColumns = @JoinColumn(name = "_role_id"))
	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}


	public static final String COLUMN_NAME = "name";

	public static final String COLUMN_PASSWORD = "password";

	public static final String COLUMN_LOCKED = "locked";
}
